import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

import 'beans/customer_bean.dart';

class Contract extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => new ListState();
}

class ListState extends State<Contract> {
  List<Map<String, dynamic>> maps = new List();
  List<String> items1 = <String>[
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'J',
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'J'
  ];

  List<Widget> doWidgets() {
    setMaps(items1);
    List<Widget> listTitles = new List();
    for (var i = 0; i < items1.length; i++) {
      listTitles.add(buildListItem(context, maps[i]));
    }
    return listTitles;
  }

  Widget buildListItem(BuildContext context, Map<String, dynamic> map) {
    return new GestureDetector(
      onTap: () {},
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new Container(
            margin: EdgeInsets.fromLTRB(20, 13, 20, 13),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Icon(
                        Icons.insert_emoticon,
                        color: const Color(0xFFff0000),
                        size: 48,
                      ),
                      SizedBox(width: 10.0),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            map['title'],
                            style: new TextStyle(
                                fontSize: 14.0, color: Colors.black),
                          ),
                          Text(
                            map['value'],
                            style: new TextStyle(
                                fontSize: 10.0, color: Colors.black54),
                          ),
                        ],
                      ),
                    ],
                  ),
                  IconButton(
                      icon: Icon(
                        Icons.phone,
                        color: Colors.blue,
                      ),
                      onPressed: () {
//              Navigator.pop(context);
                      }),
                ]),
            padding: const EdgeInsets.all(0.0),
            alignment: Alignment.center,
            width: 100,
            height: 50.0,
          ),
          Container(
            height: 1,
            color: Colors.black12,
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          '通讯录',
          style: TextStyle(color: Colors.black),
        ),
        backgroundColor: Colors.grey[400],
        leading: IconButton(
            icon: Icon(Icons.arrow_back),
            onPressed: () {
              Navigator.pop(context);
            }),
        actions: <Widget>[
          IconButton(
              icon: Icon(
                Icons.add,
                color: Colors.green,
              ),
              onPressed: () {
//              Navigator.pop(context);
              })
        ],
        elevation: 0.0,
      ),
      body: ListView.builder(
          itemCount: items1 == null ? 0 : items1.length,
          itemBuilder: (BuildContext context, int position) {
            List<Widget> temp = doWidgets();
            return temp[position];
          }),
    );
  }

  setMaps(List<String> items) {
    maps.clear();
    for (var i = 0; i < items.length; i++) {
      Map<String, dynamic> temp = {'title': '${items[i]}管理员', 'value': '无业游民'};
      maps.add(temp);
    }
  }

//  void getHttp() async {
//    //http://101.201.67.77:10017/schInfo/queryByName?schName=%E5%90%8D
//    Map data = new Map<String, dynamic>();
//    data["inscode"] = '3334499505124449';
//    try {
//      // flutter packages pub run build_runner build
//      Dio dio = new Dio();
//      dio.options.responseType = ResponseType.plain; //转字符串
//      Response response = await dio.get(
//          "http://www.hbjt.org.cn/hbjt/api/enroll/enrollCount",
//          queryParameters: data);
//      Map<String, dynamic> decoded = json.decode(response.data.toString());
//      CustomerBean testBean = CustomerBean.fromJson(decoded);
//      print(testBean.phone);
//    } catch (e) {
//      print(e);
//    }
//  }
}

//setMaps() {
//  maps.clear();
//  for (var i = 0; i < 20; i++) {
//    Map<String, dynamic> map = new Map();
//    map['name'] = '高义$i';
//    map['date'] = '2000-2-$i';
//    map['state'] = ' 潜在客户';
//    maps.add(map);
//  }
//}
